package cw;

public class ReverseString {

	/**
	 * @param args
	 */
	public static String reverse(String s) {
		char[] str = stringToCharArray(s);
		if (str == null || str.length == 0)
			return "";
		int end = str.length - 1;
		int start = 0;
		while (start < end) {
			char tmp = str[start];
			str[start++] = str[end];
			str[end--] = tmp;
		}
		return new String(str);
	}

	public static char[] stringToCharArray(String str) {
		if (str == null || str.equals(""))
			return null;

		char[] arr = new char[str.length()];
		for (int i = 0; i < str.length(); i++) {
			arr[i] = str.charAt(i);
		}
		return arr;
	}

}
